jQuery(function(t){let e=!1;function a(e){var a=t("select#product-type").val(),o=t("input#_virtual:checked").length,i=t("input#_downloadable:checked").length,r=".hide_if_downloadable, .hide_if_virtual",c=".show_if_downloadable, .show_if_virtual";t.each(woocommerce_admin_meta_boxes.product_types,function(t,e){r=r+", .hide_if_"+e,c=c+", .show_if_"+e}),t(r,e).show(),t(c,e).hide(),i&&t(".show_if_downloadable",e).show(),o&&t(".show_if_virtual",e).show(),t(".show_if_"+a,e).show(),i&&t(".hide_if_downloadable",e).hide(),o&&t(".hide_if_virtual",e).hide(),t(".hide_if_"+a,e).hide()}function o(){a(),t("input#_manage_stock").trigger("change"),t(".woocommerce_options_panel").each(function(){var e=t(this).children(".options_group");if(0!==e.length&&e.filter(function(){return"none"===t(this).css("display")}).length===e.length){var a=t(this).prop("id");t(".product_data_tabs").find('li a[href="#'+a+'"]').parent().hide()}})}function i(e){var a=t(e).next().is(".hasDatepicker")?"minDate":"maxDate",o="minDate"===a?t(e).next():t(e).prev(),i=t(e).datepicker("getDate");t(o).datepicker("option",a,i),t(e).trigger("change")}t(window).on("beforeunload",function(){e=!0}),t(function(){t('[id$="-all"] > ul.categorychecklist').each(function(){var e=t(this),a=e.find(":checked").first();if(a.length){var o=e.find("input").position().top,i=a.position().top;e.closest(".tabs-panel").scrollTop(i-o+5)}})}),t("#upsell_product_data").on("keypress",function(t){if(13===t.keyCode)return!1}),t("body").hasClass("wc-wp-version-gte-55")?t(".type_box").appendTo("#woocommerce-product-data .hndle"):t(".type_box").appendTo("#woocommerce-product-data .hndle span"),t(function(){var e=t("#woocommerce-product-data");e.find(".hndle").off("click.postboxes"),e.on("click",".hndle",function(a){t(a.target).filter("input, option, label, select").length||(e.hasClass("closed")?e.removeClass("closed"):e.addClass("closed"))})}),t("#catalog-visibility").find(".edit-catalog-visibility").on("click",function(){return t("#catalog-visibility-select").is(":hidden")&&(t("#catalog-visibility-select").slideDown("fast"),t(this).hide()),!1}),t("#catalog-visibility").find(".save-post-visibility").on("click",function(){t("#catalog-visibility-select").slideUp("fast"),t("#catalog-visibility").find(".edit-catalog-visibility").show();var e=t("input[name=_visibility]:checked").attr("data-label");return t("input[name=_featured]").is(":checked")&&(e=e+", "+woocommerce_admin_meta_boxes.featured_label,t("input[name=_featured]").attr("checked","checked")),t("#catalog-visibility-display").text(e),!1}),t("#catalog-visibility").find(".cancel-post-visibility").on("click",function(){t("#catalog-visibility-select").slideUp("fast"),t("#catalog-visibility").find(".edit-catalog-visibility").show();var e=t("#current_visibility").val(),a=t("#current_featured").val();t("input[name=_visibility]").prop("checked",!1),t("input[name=_visibility][value="+e+"]").attr("checked","checked");var o=t("input[name=_visibility]:checked").attr("data-label");return"yes"===a?(o=o+", "+woocommerce_admin_meta_boxes.featured_label,t("input[name=_featured]").attr("checked","checked")):t("input[name=_featured]").prop("checked",!1),t("#catalog-visibility-display").text(o),!1}),t("select#product-type").on("change",function(){var e,a=t(this).val();"variable"===a?(t("input#_manage_stock").trigger("change"),t("input#_downloadable").prop("checked",!1),t("input#_virtual").prop("checked",!1)):"grouped"===a?(t("input#_downloadable").prop("checked",!1),t("input#_virtual").prop("checked",!1)):"external"===a&&(t("input#_downloadable").prop("checked",!1),t("input#_virtual").prop("checked",!1)),o(),e=function(t){switch(t){case"simple":return woocommerce_admin_meta_boxes.i18n_product_simple_tip;case"grouped":return woocommerce_admin_meta_boxes.i18n_product_grouped_tip;case"external":return woocommerce_admin_meta_boxes.i18n_product_external_tip;case"variable":return woocommerce_admin_meta_boxes.i18n_product_variable_tip;default:return woocommerce_admin_meta_boxes.i18n_product_other_tip}}(a),t("#tiptip_holder").removeAttr("style"),t("#tiptip_arrow").removeAttr("style"),t(".woocommerce-product-type-tip").tipTip({attribute:"data-tip",content:e,fadeIn:50,fadeOut:50,delay:200,keepAlive:!0}),t("ul.wc-tabs li:visible").eq(0).find("a").trigger("click"),t(document.body).trigger("woocommerce-product-type-change",a,t(this))}).trigger("change"),t("input#_downloadable").on("change",function(){o()}),t("input#_virtual").on("change",function(){o(),t(this).is(":checked")&&t(".shipping_options.shipping_tab").hasClass("active")&&t(".general_options.general_tab > a").trigger("click")}),t(".sale_price_dates_fields").each(function(){var e=t(this),a=!1,o=e.closest("div, table");e.find("input").each(function(){""!==t(this).val()&&(a=!0)}),a?(o.find(".sale_schedule").hide(),o.find(".sale_price_dates_fields").show()):(o.find(".sale_schedule").show(),o.find(".sale_price_dates_fields").hide())}),t("#woocommerce-product-data").on("click",".sale_schedule",function(){var e=t(this).closest("div, table");return t(this).hide(),e.find(".cancel_sale_schedule").show(),e.find(".sale_price_dates_fields").show(),!1}),t("#woocommerce-product-data").on("click",".cancel_sale_schedule",function(){var e=t(this).closest("div, table");return t(this).hide(),e.find(".sale_schedule").show(),e.find(".sale_price_dates_fields").hide(),e.find(".sale_price_dates_fields").find("input").val(""),!1}),t("#woocommerce-product-data").on("click",".downloadable_files a.insert",function(){return t(this).closest(".downloadable_files").find("tbody").append(t(this).data("row")),!1}),t("#woocommerce-product-data").on("click",".downloadable_files a.delete",function(){return t(this).closest("tr").remove(),!1}),t("input#_manage_stock").on("change",function(){!function(e,a){const o=t(".stock_fields"),i=t(".stock_status_field");o.toggle(e),i.toggle(!e&&!i.is(".hide_if_"+a))}(t(this).is(":checked"),t("select#product-type").val()),t("input.variable_manage_stock").trigger("change")}).trigger("change"),t(".sale_price_dates_fields").each(function(){t(this).find("input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,onSelect:function(){i(t(this))}}),t(this).find("input").each(function(){i(t(this))})});const r=t(".product_attributes");if(1===r.length){t("#product_attributes").on("woocommerce_tab_shown",function(){p(),0===r.find(".woocommerce_attribute").get().length&&_()});const e=r.find(".woocommerce_attribute").get();e.sort(function(e,a){var o=parseInt(t(e).attr("rel"),10),i=parseInt(t(a).attr("rel"),10);return o<i?-1:o>i?1:0}),t(e).each(function(t,e){r.append(e)})}function c(){t(".product_attributes .woocommerce_attribute").each(function(e,a){t(".attribute_position",a).val(parseInt(t(a).index(".product_attributes .woocommerce_attribute"),10))})}var n,s,d,l=[];async function u(o){try{t("#product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});const r=t(".product_attributes .woocommerce_attribute").length,n=await function(e,a){return new Promise(function(o,i){t.post({url:woocommerce_admin_meta_boxes.ajax_url,data:{action:"woocommerce_add_attribute",product_type:t("#product-type").val(),taxonomy:a||"",i:e,security:woocommerce_admin_meta_boxes.add_attribute_nonce},success:function(t){o(t)},error:function(t,e,a){i({jqXHR:t,textStatus:e,errorThrown:a})}})})}(r,o),s=t("#product_attributes .product_attributes"),d=t(n).appendTo(s);a(d),t(document.body).trigger("wc-enhanced-select-init"),c(),d.find("h3").trigger("click"),t(document.body).trigger("woocommerce_added_attribute"),jQuery.maybe_disable_save_button()}catch(i){if(e)return;throw alert(woocommerce_admin_meta_boxes.i18n_add_attribute_error_notice),i}finally{t("#product_attributes").unblock()}}function _(){u()}function p(){const e=t(".product_attributes .woocommerce_attribute");if(1===e.length){const t=e.first(),a=t.find('input[name="attribute_names[0]"]'),o=t.find('input[name="attribute_values[0]"]');a.val()||o.val()||t.remove()}}t(".product_attributes .woocommerce_attribute").each(function(e,a){"none"!==t(a).css("display")&&t(a).is(".taxonomy")&&(l.push(t(a).data("taxonomy")),t("select.attribute_taxonomy").find('option[value="'+t(a).data("taxonomy")+'"]').attr("disabled","disabled"))}),t("select.wc-attribute-search").data("disabled-items",l),t("select.wc-attribute-search").on("select2:select",function(e){const a=e&&e.params&&e.params.data&&e.params.data.id;var o,i;return a&&(p(),u(a),i=a,function(e){t("select.wc-attribute-search").data("disabled-items",e)}(l=(o=l).includes(i)?attr:[...o,i])),t(this).val(null),t(this).trigger("change"),!1}),t("button.add_custom_attribute").on("click",function(){return _(),!1}),t(".product_attributes").on("blur","input.attribute_name",function(){var e=t(this),a=e.val(),o=e.closest(".woocommerce_attribute").find("strong.attribute_name");""===a?o.addClass("placeholder").text(woocommerce_admin_meta_boxes.i18n_attribute_name_placeholder):o.removeClass("placeholder").text(a)}),t(".product_attributes").on("click","button.select_all_attributes",function(){t(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e=t(this).closest(".woocommerce_attribute"),a={action:"woocommerce_json_search_taxonomy_terms",taxonomy:e.data("taxonomy"),security:wc_enhanced_select_params.search_taxonomy_terms_nonce};return t.get(woocommerce_admin_meta_boxes.ajax_url,a,function(a){a.errors?window.alert(a.errors):a&&a.length>0&&(a.forEach(function(t){const a=e.find('select.attribute_values option[value="'+t.term_id+'"]');a&&a.length>0?a.prop("selected","selected"):e.find("select.attribute_values").append('<option value="'+t.term_id+'" selected="selected">'+t.name+"</option>")}),e.find("select.attribute_values").trigger("change")),t(".product_attributes").unblock()}),!1}),t(".product_attributes").on("click","button.select_no_attributes",function(){return t(this).closest("td").find("select option").prop("selected",!1),t(this).closest("td").find("select").trigger("change"),!1}),t("#product_attributes").on("click",".product_attributes .remove_row",function(){var e=t(this).parent().parent();return e.find('input[name^="attribute_variation"]').is(":visible:checked")&&!window.confirm(woocommerce_admin_meta_boxes.i18n_remove_used_attribute_confirmation_message)||(e.is(".taxonomy")?(e.find("select, input[type=text]").val(""),e.hide(),t("select.attribute_taxonomy").find('option[value="'+e.data("taxonomy")+'"]').prop("disabled",!1),l=l.filter(t=>t!==e.data("taxonomy")),t("select.wc-attribute-search").data("disabled-items",l)):(e.find("select, input[type=text]").val(""),e.hide(),c()),e.remove(),window.wcTracks.recordEvent("product_attributes_buttons",{action:"remove_attribute"}),jQuery.maybe_disable_save_button()),!1}),t(".product_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style"),c()}}),t(".product_attributes").on("click","button.add_new_attribute",function(e){e.preventDefault(),t(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var a=t(this).closest(".woocommerce_attribute"),o=a.data("taxonomy"),i=window.prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(i){var r={action:"woocommerce_add_new_attribute",taxonomy:o,term:i,security:woocommerce_admin_meta_boxes.add_attribute_nonce};t.post(woocommerce_admin_meta_boxes.ajax_url,r,function(e){e.error?window.alert(e.error):e.slug&&(a.find("select.attribute_values").append('<option value="'+e.term_id+'" selected="selected">'+e.name+"</option>"),a.find("select.attribute_values").trigger("change")),t(".product_attributes").unblock()})}else t(".product_attributes").unblock()}),t(".save_attributes").on("click",function(e){if(t(this).hasClass("disabled"))e.preventDefault();else{t(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var a=t(".product_attributes").find("input, select, textarea"),i={post_id:woocommerce_admin_meta_boxes.post_id,product_type:t("#product-type").val(),data:a.serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};t.post(woocommerce_admin_meta_boxes.ajax_url,i,function(e){if(e.error)window.alert(e.error);else if(e.data){t(".product_attributes").html(e.data.html),t(".product_attributes").unblock(),o(),t("select.attribute_taxonomy").find("option").prop("disabled",!1);var a=[];t(".product_attributes .woocommerce_attribute").each(function(e,o){"none"!==t(o).css("display")&&t(o).is(".taxonomy")&&(a.push(t(o).data("taxonomy")),t("select.attribute_taxonomy").find('option[value="'+t(o).data("taxonomy")+'"]').prop("disabled",!0))}),l=a,t("select.wc-attribute-search").data("disabled-items",a);var i=window.location.toString();i=i.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),t("#variable_product_options").load(i+" #variable_product_options_inner",function(){t("#variable_product_options").trigger("reload")}),t(document.body).trigger("woocommerce_attributes_saved")}})}}),t(document.body).on("click",'#variable_product_options .add-attributes-message a[href="#product_attributes"]',function(){return t('#woocommerce-product-data .attribute_tab a[href="#product_attributes"]').trigger("click"),!1}),t(document.body).on("click",".upload_file_button",function(e){var a=t(this);if(s=a.closest("tr").find("td.file_url input"),e.preventDefault(),n)n.open();else{var o=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:a.data("choose"),priority:20,filterable:"uploaded"})];(n=wp.media.frames.downloadable_file=wp.media({title:a.data("choose"),library:{type:""},button:{text:a.data("update")},multiple:!0,states:o})).on("select",function(){var t="";n.state().get("selection").map(function(e){(e=e.toJSON()).url&&(t=e.url)}),s.val(t).trigger("change")}),n.on("ready",function(){n.uploader.options.uploader.params={type:"downloadable_product"}}),n.open()}}),t(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var m=t("#product_image_gallery"),b=t("#product_images_container").find("ul.product_images");t(".add_product_images").on("click","a",function(e){var a=t(this);e.preventDefault(),d?d.open():((d=wp.media.frames.product_gallery=wp.media({title:a.data("choose"),button:{text:a.data("update")},states:[new wp.media.controller.Library({title:a.data("choose"),filterable:"all",multiple:!0})]})).on("select",function(){var t=d.state().get("selection"),e=m.val();t.map(function(t){if((t=t.toJSON()).id){e=e?e+","+t.id:t.id;var o=t.sizes&&t.sizes.thumbnail?t.sizes.thumbnail.url:t.url;b.append('<li class="image" data-attachment_id="'+t.id+'"><img src="'+o+'" /><ul class="actions"><li><a href="#" class="delete" title="'+a.data("delete")+'">'+a.data("text")+"</a></li></ul></li>")}}),m.val(e)}),d.open())}),b.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style")},update:function(){var e="";t("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var a=t(this).attr("data-attachment_id");e=e+a+","}),m.val(e)}}),t("#product_images_container").on("click","a.delete",function(){t(this).closest("li.image").remove();var e="";return t("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var a=t(this).attr("data-attachment_id");e=e+a+","}),m.val(e),t("#tiptip_holder").removeAttr("style"),t("#tiptip_arrow").removeAttr("style"),!1}),t("#wp-content-media-buttons").append('<span class="woocommerce-help-tip" tabindex="0"></span>').find(".woocommerce-help-tip").attr("tabindex","0").attr("for","content").attr("aria-label",woocommerce_admin_meta_boxes.i18n_product_description_tip).tipTip({attribute:"data-tip",content:woocommerce_admin_meta_boxes.i18n_product_description_tip,fadeIn:50,fadeOut:50,delay:200,keepAlive:!0}),t("#postexcerpt > .postbox-header > .hndle").append('<span class="woocommerce-help-tip"></span>').find(".woocommerce-help-tip").attr("tabindex","0").attr("aria-label",woocommerce_admin_meta_boxes.i18n_product_short_description_tip).tipTip({attribute:"data-tip",content:woocommerce_admin_meta_boxes.i18n_product_short_description_tip,fadeIn:50,fadeOut:50,delay:200,keepAlive:!0});const f=t("#set-post-thumbnail"),h=`<span class="woocommerce-help-tip" tabindex="0" aria-label="${woocommerce_admin_meta_boxes.i18n_product_image_tip}"></span>`,v={attribute:"data-tip",content:woocommerce_admin_meta_boxes.i18n_product_image_tip,fadeIn:50,fadeOut:50,delay:200,keepAlive:!0};f&&t(h).insertAfter(f).tipTip(v);const w=t(".add_product_images > a");w&&t(h).insertAfter(w).tipTip(v)});